package com.cn.netty.basic;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOutboundHandlerAdapter;
import io.netty.channel.ChannelPromise;
import lombok.extern.slf4j.Slf4j;

import java.net.SocketAddress;

@Slf4j
public class EchoServerOutboundHandlerOne extends ChannelOutboundHandlerAdapter {

  @Override
  public void bind(ChannelHandlerContext ctx, SocketAddress localAddress,
                   ChannelPromise promise) throws Exception {
    //TODO 写上没有
    log.warn("bind -> {} ,localAddress -> {} ,promise -> {}", ctx, localAddress, promise);
  }

//  @Override
//  public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {  //TODO 写上没有
//    log.warn("close -> {}", promise);
//  }

  @Override
  public void read(ChannelHandlerContext ctx) throws Exception {
    log.warn("read event");
    super.read(ctx);
  }

  @Override
  public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
    //每执行一次write(),我都要触发一次
    log.warn("write event -> {}",String.valueOf(msg));
    super.write(ctx, msg, promise);
  }

}
